<?php

// +----------------------------------------------------------------------
// | ThinkAdmin
// +----------------------------------------------------------------------
// | 版权所有 2014~2017 广州楚才信息科技有限公司 [ http://www.cuci.cc ]
// +----------------------------------------------------------------------
// | 官方网站: http://think.ctolog.com
// +----------------------------------------------------------------------
// | 开源协议 ( https://mit-license.org )
// +----------------------------------------------------------------------
// | github开源项目：https://github.com/zoujingli/ThinkAdmin
// +----------------------------------------------------------------------

namespace app\admin\controller;

use controller\BasicAdmin;
use service\DataService;
use think\Db;

/**
 * 系统日志管理
 * Class Log
 * @package app\admin\controller
 * @author Anyon <zoujingli@qq.com>
 * @date 2017/02/15 18:12
 */
class Lettery extends BasicAdmin
{

    /**
     * 指定当前数据表
     * @var string
     */
    public $table = 'sys_lettery';


    public function index()
    {
        $actions = Db::name($this->table);
        $this->assign('actions', $actions);
        // 日志数据库对象
        list($this->title, $get) = ['等级设置', $this->request->get()];
        $db = Db::name($this->table)
            ->alias('a')
            ->join('store_shops b','a.shop_id = b.id')
            ->field("a.*,b.shop_name")
            ->order('id');
        if (isset($get['create_at']) && $get['create_at'] !== '') {
            list($start, $end) = explode(' - ', $get['create_at']);
            $db->whereBetween('create_at', ["{$start} 00:00:00", "{$end} 23:59:59"]);
        }
        if (isset($get['shop']) && $get['shop'] !== ''){
            $db->where('b.shop_name', 'like',"%{$get['shop']}%");
//            $db->where('b.shop_name',$get['shop']);
        }

        return parent::_list($db);
    }


    public function del()
    {
        if (DataService::update($this->table)) {
            $this->success("抽奖设置删除成功!", '');
        }
        $this->error("抽奖设置删除失败, 请稍候再试!");
    }


    public function add()
    {
        $sys_level = Db::name('store_shops')->where('is_disable = 1')->select();
        $this->assign('sys_level', $sys_level);
        return $this->_form($this->table, 'form', '', '');
    }

    public function edit()
    {
        $sys_level = Db::name('store_shops')->where('is_disable = 1')->select();
        $this->assign('sys_level', $sys_level);
        return $this->_form($this->table, 'form');
    }

}
